package zkk.com.mengqu.simplepreferences;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import java.util.Map;
import java.util.Set;

public class Share {
	public static final String USERNAME = "USERNAME";
	public static final String UID = "UID";
	public static final String TOKEN = "TOKEN";
	public static final String SEX = "SEX";
	public static final String ADDRESS = "ADDRESS";
	public static final String PHONE = "PHONE";
	public static final String ICON = "ICON";

	//当前经纬度坐标
	public static final String LATITUDE = "LATITUDE";//经度
	public static final String LONGITUDE = "LONGITUDE";//经度

	private static final String SHARE_PREFERENCE_NAME = "Cengceng";
	private static SharedPreferences share;
	private static SharedPreferences.Editor editor;

	public static SharedPreferences create(Context context){
		share = context.getSharedPreferences(SHARE_PREFERENCE_NAME, Activity.MODE_PRIVATE);
		editor = share.edit();
		return share;
	}

	public static void setShare(Map<String, String> maps){
		Set<Map.Entry<String,String>> entrySet = maps.entrySet();
		for (Map.Entry<String,String> entry: entrySet){
			editor.putString(entry.getKey(),entry.getValue());
		}
		editor.commit();
	}

	public static void logout(){
		editor.remove(USERNAME);
		editor.remove(UID);
		editor.remove(TOKEN);
		editor.remove(SEX);
		editor.remove(ADDRESS);
		editor.remove(PHONE);
		editor.remove(ICON);
		editor.commit();
	}

	//获取保存的用户id
	public static String getUserId(){
		return share.getString(UID,"null");
	}

	//获取保存的用户token
	public static String getUserToken(){
		return share.getString(TOKEN,"null");
	}

	//获取保存的用户token
	public static String getUserName(){
		return share.getString(USERNAME,"null");
	}

	public static String getUserSex(){
		return share.getString(SEX,"null");
	}

	public static String getUserAddress(){
		return share.getString(ADDRESS,"null");
	}

	public static String getUserPhone(){
		return share.getString(PHONE, "null");
	}

	public static String getIcon(){
		return share.getString(ICON, "null");
	}

	public static String getLatitude(){
		return share.getString(LATITUDE, "null");
	}

	public static String getLongitude(){
		return share.getString(LONGITUDE, "null");
	}
}
